/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */
package com.ykht.proj.coupon.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.entity.CnCare;
import com.ykht.proj.coupon.entity.CnCoupon;
import com.ykht.proj.coupon.mapper.CnCareMapper;
import com.ykht.proj.coupon.mapper.CnCouShopMapper;
import com.ykht.proj.coupon.service.CnBrandService;
import com.ykht.proj.coupon.service.CnCareService;
import com.ykht.proj.coupon.service.CnCouShopService;
import com.ykht.proj.coupon.service.CnCouponService;
import com.ykht.proj.coupon.vo.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 关注表
 *
 * @author proj code generator
 * @date 2020-11-16 17:00:21
 */
@Service
@RequiredArgsConstructor
public class CnCareServiceImpl extends ServiceImpl<CnCareMapper, CnCare> implements CnCareService {
	private final CnCareMapper cnCareMapper;
	private final CnCouShopMapper cnCouShopMapper;
	private final CnCouponService cnCouponService;
	private final CnCouShopService cnCouShopService;
	private final CnBrandService cnBrandService;

	@Override
	public IPage<CnCarePageResp> opPage(Page page, CnCare cnCare) {

		cnCare.setPerId(SecurityUtils.getPersonId());
		IPage<CnCarePageResp> temp = cnCouShopMapper.opPage(page,cnCare);

		//使用多线程并行流进行遍历提高速度
		temp.getRecords().parallelStream().collect(Collectors.toList()).forEach(o->{
			PinPaiGuanVo pinPaiGuanVo = cnBrandService.pinPaiGuan(o.getBrandId());
			BeanUtil.copyProperties(pinPaiGuanVo,o,new CopyOptions().ignoreNullValue());
		});
		return temp;
	}
}
